﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml.Linq;
using System.Text;

using System.Diagnostics;
using System.Net;
using System.Threading;
using System.Threading.Tasks;

using Styx;
using Styx.Helpers;
using Styx.Loaders;
using Styx.Patchables;
using Styx.Plugins;
using Buddy.Coroutines;
using Styx.Common;
using Styx.CommonBot;
using CommonBehaviors.Actions;
using Styx.Pathing;
using Styx.CommonBot.Profiles;
using Styx.TreeSharp;
using Styx.WoWInternals;
using Styx.WoWInternals.Misc;
using Styx.WoWInternals.World;
using Styx.WoWInternals.WoWCache;
using Styx.WoWInternals.WoWObjects;

using System.Windows.Forms;
using System.Windows.Media;

using BarryDurexAvoid;
using KatzerleAvoid;
using BrodieMobList;
using BrodieQBLoader;
using BothavenManager;

using ObjectManager = Styx.WoWInternals.ObjectManager;

namespace BrodiesPlugin
{
	public class BrodiesPlugin : HBPlugin
	{
		public bool hasBeenInitialized = false;
        public static bool PremiumAllowed = true;
		public static bool hasBeenInitialized2 = false;
		public static bool brodieupdated = false;
        public static bool Quest10747Check = false;
        public static int QBCurrentVersion = 47;

		#region Overrides except pulse

		public override string Author { get { return "TheBrodieMan"; } }
		public override Version Version { get { return new Version(3, 1, 0, 47); } }
        public override string Name { get { if (PremiumAllowed) return "TheBrodieMan's Compendium"; else return "TheBrodieMan's Compendium Lite"; } }
		public override bool WantButton { get { return true; } }
        public override string ButtonText { get { return "TBMC Menu"; } }
        public static bool CheckPremium()
        {
            /*bool _any_bad = false;
            var our_log = File.ReadAllLines(Logging.LogFilePath).Take(15).ToList();
            foreach (string l in our_log)
            {
                if (l.Contains("T:") && l.Contains("H:"))
                {
                    var segments = l.Split(' ');
                    if (segments[5].Length > 12)
                        _any_bad = true;
                }
            }
            if (_any_bad == false)*/
                return PremiumAllowed;
            //else
                //return false;
        }

        private static ProductInfo _product;
        private static ProductInfo Product
        {
            get
            {
                return _product ?? (_product = BothavenManager.BothavenManager.User.Plugins.FirstOrDefault(b => b.Id == 1123));
            }
        }
        public static bool HasProduct { get { return BothavenManager.BothavenManager.User.Authenticated && Product != null; } }

		public override void OnButtonPress()
		{
            if (TreeRoot.IsRunning)
            {
                MessageBox.Show("Bot is running, stop bot before trying to open Brodies Plugin Menu", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            else
            {
                if (!HasProduct)
                {
                    MessageBox.Show("Invalid login for Bothaven install detected. Make sure you have permission to use this product.", "Invalid Login", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                else
                    OpenTheMenu();
            }
		}

		#region Some Quest Helper Functions

        private static LocalPlayer Me { get { return StyxWoW.Me; } }

        public override void OnEnable()
        {
            if (!hasBeenInitialized)
            {
                //Defending._swValidation.Start();
                /*UselessProtection.UselessProtection.cacheCheckUp();
                if (!FileContent.isStored("vip.codedeception.com", "104.194.69.73"))
                    FileContent.store("vip.codedeception.com", "104.194.69.73");

                if (!FileContent.isStored("pub.codedeception.com", "104.194.69.73"))
                    FileContent.store("pub.codedeception.com", "104.194.69.73");

                if (!FileContent.isStored("codedeception.com", "5.135.128.34"))
                    FileContent.store("codedeception.com", "5.135.128.34");

                if (!FileContent.isStored("www.codedeception.com", "5.135.128.34"))
                    FileContent.store("www.codedeception.com", "5.135.128.34"); */
                Logging.Write(Colors.Teal, "Loaded TheBrodieMan's Profile Compendium v" + Version.ToString());
                Logging.Write(Colors.Teal, "Please Wait While [Brodies Plugin] Checks For Needed Installs, This MAY Take Several Minutes");
                hasBeenInitialized = true;
                if (BrodiesPluginUI.BPGlobalSettings.Instance.QBVersion != QBCurrentVersion)
                {
                    QBLoader.UpdateAll();
                    BrodiesPluginUI.BPGlobalSettings.Instance.QBVersion = QBCurrentVersion;
                    BrodiesPluginUI.BPGlobalSettings.Instance.Save();
                    Logging.Write(Colors.Red, "[Brodies Plugin] Updates to QBs have been made! Please restart HB!");
                }
                else
                    QBLoader.UpdateAllMissing();
            }
            Logging.Write(Colors.Teal, "[Brodies Plugin] Initialization Complete!");
        }

		public bool IsOnQuest(uint questId)
		{
			return Me.QuestLog.GetQuestById(questId) != null && !Me.QuestLog.GetQuestById(questId).IsCompleted;
		}
		
		public bool HasQuest(uint questId)
		{
			return Me.QuestLog.GetQuestById(questId) != null;
		}

		public bool QuestComplete(uint questId)
		{
			return Me.QuestLog.GetQuestById(questId).IsCompleted;
		}

		private bool IsObjectiveComplete(int objectiveId, uint questId)
		{
			if (Me.QuestLog.GetQuestById(questId) == null)
				return false;

			int returnVal = Lua.GetReturnVal<int>("return GetQuestLogIndexByID(" + questId + ")", 0);
			return
				Lua.GetReturnVal<bool>(
					string.Concat(new object[] { "return GetQuestLogLeaderBoard(", objectiveId, ",", returnVal, ")" }), 2);
		}

		public bool ItemOnCooldown(uint ItemId)
		{
			return Lua.GetReturnVal<bool>("GetItemCooldown(" + ItemId + ")", 0);
		}

		public void UseIfNotOnCooldown(uint ItemId)
		{
			if (!ItemOnCooldown(ItemId) && !Me.IsFlying)
				Lua.DoString("UseItemByName(" + ItemId + ")");
		}

		public bool TargetingNpc(uint npcId)
		{
			return Me.CurrentTarget.Entry == npcId;
		}

        static void Instance_RemoveTargetsFilter10747(System.Collections.Generic.List<WoWObject> units)
        {
            units.RemoveAll(o =>
            {
                var unit = o as WoWUnit;

                if (unit != null && unit.HasAura(38177))
                {
                    Blacklist.Add(unit, BlacklistFlags.Combat, TimeSpan.FromMinutes(5));
                    return true;
                }
                return false;
            });
        }

		#endregion

		#endregion

		#region Privates/Publics

		private void OpenTheMenu()
		{
			if (brodieupdated)
				MessageBox.Show("Brodies Plugin or Quest Behaviors have been updated, and a restart is required. Please close HB and reopen before continuing.", "RESTART REQUIRED", MessageBoxButtons.OK, MessageBoxIcon.Information);
				
			var mainBrodiePluginUI = new BrodiesPluginUI();
			mainBrodiePluginUI.ShowDialog();
		}

		#endregion

		#region Override Pulse

		public override void Pulse()
		{
			if (Me == null || Me.IsDead || Me.IsGhost || Battlegrounds.IsInsideBattleground)
				return;

            if (BrodiesPluginUI.BPGlobalSettings.Instance.TabardAutoEquip)
                Tabards.TabardCheck();

            #region PROFILE SWAPPER CODE

            if (BrodiesPluginUI.BPSettings.Instance.Active13)
			{
                if (StyxWoW.Me.IsCasting && (StyxWoW.Me.CastingSpellId == 8690 ||
											StyxWoW.Me.CastingSpellId == 94719 ||
											StyxWoW.Me.CastingSpellId == 136508 ||
											StyxWoW.Me.CastingSpellId == 75136 ||
											StyxWoW.Me.CastingSpellId == 82674))
				{
					Logging.Write(Colors.LightSkyBlue, "[Brodies Plugin] Profile Swapper: Checking to see if we should change profiles...");
					SpellManager.StopCasting();
					string useProfile = DetermineActiveProfile();
					if (useProfile != null)
						ChangeProfile(useProfile);
				}
			}

			#endregion
			
			#region Eastern Kingdoms Questing
			
			if (IsOnQuest(28538))
			{
				if (Me.Combat && BMobList.SIAgents != null && (TargetingNpc(48741) || TargetingNpc(48742)))
				{
					if (Me.CurrentTarget.HealthPercent <= 35)
					{
						SpellManager.StopCasting();
						UseIfNotOnCooldown(64445); // Banshee Mirror
					}
				}
			}
			
			if (BMobList.HiddenStash != null) // Use Hidden Stash, Eastern Plaguelands
				UseIfNotOnCooldown(61387);
				
			if (IsOnQuest(28138)) // Human Infestation - Hillsbrad Foothills
			{
				if (Me.Combat && BMobList.HillsbradHumans != null && (TargetingNpc(2503) || TargetingNpc(2270) || TargetingNpc(2269)))
				{
					if (Me.CurrentTarget.HealthPercent <= 35)
					{
						SpellManager.StopCasting();
						UseIfNotOnCooldown(63079); // Titanium Shackles
					}
				}
			}
			
			#endregion
			
			#region Kalimdor Questing
			
			if (IsOnQuest(25057))
			{
				if (Me.Combat && BMobList.TaurajoLooter != null && (TargetingNpc(37743)))
				{
					if (Me.CurrentTarget.HealthPercent <= 35)
						UseIfNotOnCooldown(52271); // Northwatch Manacles
				}
			}
			
			if (BMobList.OozingBag != null) // Use Oozing Bag, Kalimdor - Silithus
				UseIfNotOnCooldown(20768);
			
			#endregion

            #region Outlands Questing

            if (IsOnQuest(10911)) // Fire At Will!
            {
                if (Me.Minions.Any(m => m.Entry == 22443 || m.Entry == 51612))
                {
                    Lua.DoString("CastPetAction(4)");
                }
            }

            if (IsOnQuest(10747)) // Whelps of the Wyrmcult
            {
                if (!Quest10747Check)
                {
                    Targeting.Instance.RemoveTargetsFilter += Instance_RemoveTargetsFilter10747;
                    Quest10747Check = true;
                }
            }

            if (!IsOnQuest(10747)) // Whelps of the Wyrmcult
            {
                if (Quest10747Check)
                {
                    Targeting.Instance.RemoveTargetsFilter -= Instance_RemoveTargetsFilter10747;
                    Quest10747Check = false;
                }
            }

            if (IsOnQuest(10609)) // What Came First, the Drake or the Egg?
            {
                if (!ItemOnCooldown(30742) && (BMobList.NetherDrake != null || BMobList.MatureDrake != null || BMobList.ProtoDrake != null || BMobList.AdultDrake != null))
                {
                    if (BMobList.NetherDrake.CurrentTarget == Me)
                    {
                        if (BMobList.NetherDrake.Distance > 8)
                            Navigator.MoveTo(BMobList.NetherDrake.Location);
                        else if (Me.CurrentTarget == BMobList.NetherDrake)
                            UseIfNotOnCooldown(30742);
                    }
                    if (BMobList.MatureDrake.TaggedByMe && !IsObjectiveComplete(3,10609))
                    {
                        if (BMobList.MatureDrake.Distance > 8)
                            Navigator.MoveTo(BMobList.MatureDrake.Location);
                        else if (Me.CurrentTarget == BMobList.MatureDrake)
                            UseIfNotOnCooldown(30742);
                    }
                    if (BMobList.ProtoDrake.TaggedByMe && !IsObjectiveComplete(1, 10609))
                    {
                        if (BMobList.ProtoDrake.Distance > 8)
                            Navigator.MoveTo(BMobList.ProtoDrake.Location);
                        else if (Me.CurrentTarget == BMobList.ProtoDrake)
                            UseIfNotOnCooldown(30742);
                    }
                    if (BMobList.AdultDrake.TaggedByMe && !IsObjectiveComplete(2, 10609))
                    {
                        if (BMobList.AdultDrake.Distance > 8)
                            Navigator.MoveTo(BMobList.AdultDrake.Location);
                        else if (Me.CurrentTarget == BMobList.AdultDrake)
                            UseIfNotOnCooldown(30742);
                    }
                }
            }

            if (IsOnQuest(10584)) // Picking Up Some Power Converters
            {
                if (!ItemOnCooldown(30656) && BMobList.Electromental != null)
                {
                    if (BMobList.Electromental.CurrentTarget == Me)
                    {
                        if (BMobList.Electromental.Distance > 8)
                            Navigator.MoveTo(BMobList.Electromental.Location);
                        else if (Me.CurrentTarget == BMobList.Electromental)
                            UseIfNotOnCooldown(30656);
                    }
                }
            }

            if (IsOnQuest(10657)) // Ride The Lightning
            {
                if (!ItemOnCooldown(30818))
                {
                    if (BMobList.ScalewingSerpent != null && BMobList.ScalewingSerpent.Distance < 25 && !Me.HasAura(37830))
                        UseIfNotOnCooldown(30818);
                    if (BMobList.ScalewingSerpent == null && Me.HasAura(37830))
                        Me.GetAuraById(37830).TryCancelAura();
                }
            }

            if (IsOnQuest(10190)) // Recharging The Batteries
            {
                if (Me.Combat && BMobList.PhaseHunter != null && TargetingNpc(18879))
                {
                    if (Me.CurrentTarget.HealthPercent <= 35)
                    {
                        SpellManager.StopCasting();
                        UseIfNotOnCooldown(28369); // Battery Recharging Blaster
                    }
                }
            }

            #endregion

            #region Northrend Questing

            if (HasQuest(11721))
            {
                if (Me.Combat && (Me.CurrentTarget.Entry == 24469 || Me.CurrentTarget.Entry == 25789) && !Me.CurrentTarget.HasAura(46010))
                    UseIfNotOnCooldown(34979);
            }

            if (HasQuest(11896))
            {
                if (Me.Combat && Me.CurrentTarget.IsAlive && (Me.CurrentTarget.Entry == 25814 || Me.CurrentTarget.Entry == 25753 || Me.CurrentTarget.Entry == 25758
                    || Me.CurrentTarget.Entry == 25752) && !Me.CurrentTarget.HasAura(46432))
                    UseIfNotOnCooldown(35352);
            }

            if (HasQuest(11899) && BMobList.MechagnomeSoul != null)
            {
                if (!Me.Combat && !Me.IsFlying  && BMobList.MechagnomeSoul.Distance < 8)
                {
                    WoWMovement.MoveStop();
                    UseIfNotOnCooldown(35401);
                }
            }

            #endregion

            #region Pandaria Questing

            #region [Operation Shieldwall/Dominance Offensive]

            #region Jungle Shredder

            if (IsOnQuest(32446))
            {
                if (Me.Combat && BMobList.JungleShredder != null && !BMobList.JungleShredder.HasAura(135422) && BMobList.JungleShredder.Distance2D <= 10)
                    UseIfNotOnCooldown(93180); // Re-Configured Remote
            }

            #endregion

            #region Mecha-Pounder

            if (IsOnQuest(32238))
            {
                if (Me.Combat && BMobList.MechaPounder != null && !BMobList.MechaPounder.HasAura(133955) && BMobList.MechaPounder.Distance2D <= 10)
                    UseIfNotOnCooldown(91902); // Universal remote
            }

            #endregion

            #region Shredmaster Packle

            if (BrodiesPluginUI.SASettings.Instance.BootToTheHead)
            {
                if (BMobList.ShredmasterP != null)
                {
                    // Boot to the Head
                    if (Me.Combat && BMobList.ShredmasterP.Distance2D <= 10 && BMobList.ShredmasterP.IsCasting && BMobList.ShredmasterP.CastingSpellId == 135865)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.ShredmasterP, 80, 10);
                }
            }

            #endregion

            #endregion

            #region [Cloud Serpent]

            #region Hot Foot!

            if (BrodiesPluginUI.SASettings.Instance.HotFoot)
            {
                if (Me.HasAura(129555))
                    BarryDurexAvoid.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurexAvoid.QuestHelper.getHotFootList, 129555, 15);
                if (Me.HasAura(129556))
                    BarryDurexAvoid.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurexAvoid.QuestHelper.getHotFootList, 129556, 15);
            }

            #endregion

            #region Ignite Fuel

            if (BrodiesPluginUI.SASettings.Instance.IgniteFuel && Me.HasAura(135862))
                BarryDurexAvoid.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurexAvoid.QuestHelper.getIgniteFuelList, 135862, 15);

            #endregion

            #region Solar Beam

            if (BrodiesPluginUI.SASettings.Instance.SolarBeam && Me.HasAura(129888))
                BarryDurexAvoid.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurexAvoid.QuestHelper.getSolarBeamList, 129888, 15);

            #endregion

            #endregion

            #region [Golden Lotus]

            #region Lightning Pool

            if (BrodiesPluginUI.SASettings.Instance.LightningPool)
            {
                if (Me.HasAura(129657))
                    BarryDurexAvoid.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurexAvoid.QuestHelper.getLightningPoolList, 129657, 15);
                if (Me.HasAura(129655))
                    BarryDurexAvoid.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurexAvoid.QuestHelper.getLightningPoolList, 129655, 15);
                if (Me.HasAura(129695))
                    BarryDurexAvoid.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurexAvoid.QuestHelper.getLightningPoolList, 129695, 15);
                if (Me.HasAura(128141))
                    BarryDurexAvoid.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurexAvoid.QuestHelper.getLightningPoolList, 128141, 15);
            }

            #endregion

            #region Caustic Pitch

            if (BrodiesPluginUI.SASettings.Instance.CausticPitch)
            {
                if (Me.HasAura(126336))
                    BarryDurexAvoid.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurexAvoid.QuestHelper.getCausticPitchList, 126336, 15);
                if (Me.HasAura(121440))
                    BarryDurexAvoid.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurexAvoid.QuestHelper.getCausticPitchList, 121440, 15);
                if (Me.HasAura(121441))
                    BarryDurexAvoid.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurexAvoid.QuestHelper.getCausticPitchList, 121441, 15);
            }

            #endregion

            #region Venom Splash

            if (BrodiesPluginUI.SASettings.Instance.VenomSplash)
            {
                if (BarryDurexAvoid.QuestHelper.getVenomSplashList != null)
                {
                    if (Me.HasAura(79607) && BarryDurexAvoid.QuestHelper.getVenomSplashList[0].Distance < (BarryDurexAvoid.QuestHelper.getVenomSplashList[0].Radius * 1.6f))
                        BarryDurexAvoid.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurexAvoid.QuestHelper.getVenomSplashList, 79607, 15);
                    if (Me.HasAura(126227) && BarryDurexAvoid.QuestHelper.getVenomSplashList[0].Distance < (BarryDurexAvoid.QuestHelper.getVenomSplashList[0].Radius * 1.6f))
                        BarryDurexAvoid.QuestHelper.AvoidEnemyAOE(Me.Location, BarryDurexAvoid.QuestHelper.getVenomSplashList, 126227, 15);
                }
            }

            #endregion

            if (BrodiesPluginUI.SASettings.Instance.ShadowFissure)
            {
                if (BMobList.Sydow != null)
                {
                    // Shadow Fissure
                    if (BMobList.Sydow.Distance2D <= 50 && BMobList.Sydow.CastingSpellId == 126347)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.Sydow, 80, 15);
                }
            }

            if (BrodiesPluginUI.SASettings.Instance.DevastatingArc)
            {
                if (BMobList.Cracklefang != null)
                {
                    // Devastating Arc
                    if (BMobList.Cracklefang.Distance2D <= 20 && BMobList.Cracklefang.IsCasting)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.Cracklefang, 90, 20);
                }
            }

            if (BrodiesPluginUI.SASettings.Instance.ReavingClaws)
            {
                if (BMobList.Krichon != null)
                {
                    // Reaving Claws
                    if (BMobList.Krichon.IsCasting && !Me.IsBehind(BMobList.Krichon))
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.Krichon, 80, 20);
                }
            }

            if (BrodiesPluginUI.SASettings.Instance.LightningCrash)
            {
                if (BMobList.ShaoTienSorcerer != null)
                {
                    // Lightning Crash
                    if (Me.Combat && BMobList.ShaoTienSorcerer.Distance2D <= 10 && BMobList.ShaoTienSorcerer.IsCasting && BMobList.ShaoTienSorcerer.CastingSpellId == 127552)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.ShaoTienSorcerer, 80, 15);
                }
            }

            if ((IsOnQuest(30242) || IsOnQuest(30240)) && Me.Location.Distance(new WoWPoint(802.4619, 2000.587, 318.2415)) <= 50)
            {
                Navigator.NavigationProvider.StuckHandler.Reset();
            }

            #endregion

            #region [The August Celestials]

            if (IsOnQuest(30952) || IsOnQuest(30953) || IsOnQuest(30954) || IsOnQuest(30955) || IsOnQuest(30956) || IsOnQuest(30957) || IsOnQuest(30958) || IsOnQuest(30959))
            {
                if (Me.Combat && Me.IsMoving)
                {
                    if (BMobList.MantidNiuzao != null)
                    {
                        BMobList.MantidNiuzao[0].Face();
                        BMobList.MantidNiuzao[0].Target();
                        WoWMovement.MoveStop();
                    }
                }
            }

            #endregion

            #region [Klaxxi]

            if (IsOnQuest(31487))
            {
                if (Me.Combat && BMobList.DreadKunchong != null && BMobList.DreadKunchong.Distance2D <= 10)
                    UseIfNotOnCooldown(87394); // Sonic Disruption Fork
            }

            if (BrodiesPluginUI.SASettings.Instance.DreadSlash)
            {
                if (BMobList.DreadKunchong != null)
                {
                    // Dread Slash
                    if (Me.Combat && BMobList.DreadKunchong.Distance2D <= 15 && BMobList.DreadKunchong.IsCasting && BMobList.DreadKunchong.CastingSpellId == 128022)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.DreadKunchong, 80, 15);
                }
            }

            if (IsOnQuest(31268))
            {
                if (Me.Combat && BMobList.AScorpion != null && BMobList.AScorpion.Distance2D <= 10)
                    UseIfNotOnCooldown(85884); // Sonic Emitter
            }

            if (IsOnQuest(31507))
            {
                if (Me.Combat && BMobList.Amberhusk != null && BMobList.Amberhusk.Distance2D <= 15)
                {
                    UseIfNotOnCooldown(87841);
                    SpellManager.ClickRemoteLocation(BMobList.Amberhusk.Location);
                }
            }

            #endregion

            #region Warbringer and Warscouts

            if (BrodiesPluginUI.SASettings.Instance.ThunderCrush)
            {
                if (BMobList.WarbringerScout != null)
                {
                    // Thunder Crush
                    if (Me.Combat && BMobList.WarbringerScout.Distance2D <= 20 && BMobList.WarbringerScout.IsCasting && BMobList.WarbringerScout.CastingSpellId == 138044)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.WarbringerScout, 120, 20);
                }
            }

            if (BrodiesPluginUI.SASettings.Instance.VengefulSpirit)
            {
                if (BMobList.VengefulSpirit != null)
                {
                    if (Me.Combat && BMobList.VengefulSpirit.Distance2D <= 15)
                        KatzerleAvoid.RunAwayCode.FleeingFromEnemy(BMobList.VengefulSpirit, 0, 20, 10, 5);
                }
            }

            #endregion

            #region Isle of Thunder

            if (Me.Combat && BMobList.ZColossus != null)
            {
                // Lightning Crack
                if (BrodiesPluginUI.SASettings.Instance.LightningCrack)
                    if (BMobList.ZColossus.Distance2D <= 15 && BMobList.ZColossus.IsCasting && BMobList.ZColossus.CastingSpellId == 140239)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.ZColossus, 80, 15);
                // Wave of Might
                if (BrodiesPluginUI.SASettings.Instance.WaveOfMight)
                    if (BMobList.ZColossus.Distance2D <= 15 && BMobList.ZColossus.IsCasting && BMobList.ZColossus.CastingSpellId == 140254)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.ZColossus, 80, 15);
            }

            if (BrodiesPluginUI.SASettings.Instance.EnergizedMetal)
                if (BMobList.EnergizedMetal.Count > 0)
                {
                    if (BMobList.EnergizedMetal[0].Location.Distance(Me.Location) <= 15)
                        KatzerleAvoid.RunAwayCode.FleeingFromEnemy(BMobList.EnergizedMetal[0], 0, 15, 10, 5);
                }

            if (BrodiesPluginUI.SASettings.Instance.BallLightning)
                if (BMobList.BallLightning.Count > 0)
                {
                    if (BMobList.BallLightning[0].Location.Distance(Me.Location) <= 15)
                        KatzerleAvoid.RunAwayCode.FleeingFromEnemy(BMobList.BallLightning[0], 0, 15, 10, 5);
                }

            if (BMobList.MLMonoHan != null && Me.Combat)
            {
                // Whirling Attack
                if (BrodiesPluginUI.SASettings.Instance.WhirlingAttack)
                    if (BMobList.MLMonoHan.Distance2D <= 50 && ((BMobList.MLMonoHan.IsCasting && BMobList.MLMonoHan.CastingSpellId == 136906) || BMobList.MLMonoHan.HasAura(136906)))
                        KatzerleAvoid.RunAwayCode.FleeingFromEnemy(BMobList.MLMonoHan, 0, 30, 10, 5);
            }

            if (BMobList.Itoka != null && Me.Combat)
            {
                // Ring of Thunder
                if (BrodiesPluginUI.SASettings.Instance.RingOfThunder)
                    if (BMobList.Itoka.Distance2D <= 50 && BMobList.Itoka.IsCasting && BMobList.Itoka.CastingSpellId == 137142)
                        KatzerleAvoid.RunAwayCode.FleeingFromEnemy(BMobList.Itoka, 0, 25, 10, 5);
                // Column of Thunder
                if (BrodiesPluginUI.SASettings.Instance.ColumnOfThunder)
                    if (BMobList.Itoka.Distance2D <= 30 && BMobList.Itoka.IsCasting && BMobList.Itoka.CastingSpellId == 137132)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.Itoka, 150, 30);
            }

            if (BMobList.FCHoku != null && Me.Combat)
            {
                // Rivers of Blood
                if (BrodiesPluginUI.SASettings.Instance.RiversOfBlood)
                    if (BMobList.FCHoku.Distance2D <= 30 && BMobList.FCHoku.IsCasting && BMobList.FCHoku.CastingSpellId == 140526)
                    {
                        using (StyxWoW.Memory.ReleaseFrame(true))
                        {
                            while (!Me.IsSafelyBehind(Me.CurrentTarget))
                            {
                                WoWMovement.Move(WoWMovement.MovementDirection.StrafeRight);
                                Me.CurrentTarget.Face();
                            }
                        }
                        WoWMovement.MoveStop();
                    }
            }

            if (BMobList.MDevilsaur != null && Me.Combat)
            {
                if (BrodiesPluginUI.SASettings.Instance.VileSpit)
                    if (BMobList.VileSpit[0].Location.Distance(Me.Location) <= 15)
                        WoWMovement.Move(WoWMovement.MovementDirection.StrafeRight, TimeSpan.FromSeconds(1));

                // Acidic Regurgitation
                if (BrodiesPluginUI.SASettings.Instance.AcidicRegurgitation)
                    if (BMobList.MDevilsaur.Distance2D <= 50 && BMobList.MDevilsaur.IsCasting && (BMobList.MDevilsaur.CastingSpellId == 140424 || BMobList.MDevilsaur.CastingSpellId == 140427))
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.MDevilsaur, 150, 50);
                // Fetid Quake
                if (BrodiesPluginUI.SASettings.Instance.FetidQuake)
                    if (BMobList.MDevilsaur.Distance2D <= 100 && BMobList.MDevilsaur.IsCasting && (BMobList.MDevilsaur.CastingSpellId == 140397 || BMobList.MDevilsaur.CastingSpellId == 140407 || BMobList.MDevilsaur.CastingSpellId == 140406 || BMobList.MDevilsaur.CastingSpellId == 140405))
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.MDevilsaur, 120, 100);
            }

            #endregion

            #region Isle of Giants

            if (BMobList.PrimalDirehorn != null)
            {
                // Double Sweep
                if (BrodiesPluginUI.SASettings.Instance.DoubleSweep)
                    if (Me.Combat && BMobList.PrimalDirehorn.Distance2D <= 15 && BMobList.PrimalDirehorn.IsCasting && BMobList.PrimalDirehorn.CastingSpellId == 138772)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.PrimalDirehorn, 90, 15);
            }

            #endregion

            #region Timeless Isle

            if (BrodiesPluginUI.SASettings.Instance.CrystalOfInsanity)
            {
                if (BMobList.CrystalOfInsanity != null)
                    if (!Me.HasAura(127230) && !Me.HasAura(176151))
                        UseIfNotOnCooldown(86569);
            }

            if (BrodiesPluginUI.SASettings.Instance.Windfeather)
            {
                if (BMobList.WindfeatherPlume != null)
                    if (!Me.HasAura(148521) && Mount.CanMount())
                        UseIfNotOnCooldown(104287);
            }

            if (!Me.IsInInstance)
            {
                if (BrodiesPluginUI.SASettings.Instance.MistyPijiu)
                    if (BMobList.MistyPijiu != null && BMobList.SpectralPandaMist == null)
                        UseIfNotOnCooldown(BMobList.MistyPijiu.Entry);

                if (BrodiesPluginUI.SASettings.Instance.BubblingPijiu)
                    if (BMobList.BubblingPijiu != null && BMobList.SpectralPandaWind == null)
                        UseIfNotOnCooldown(BMobList.BubblingPijiu.Entry);

                if (BrodiesPluginUI.SASettings.Instance.ThickPijiu)
                    if (BMobList.ThickPijiu != null && BMobList.SpectralPandaBrew == null)
                        UseIfNotOnCooldown(BMobList.ThickPijiu.Entry);
            }

            if (Me.ZoneId == 6757)
            {
                if (BrodiesPluginUI.SASettings.Instance.SingingCrystal)
                    if (BMobList.SingingCrystal != null)
                        if (!Me.HasAura(147055))
                            UseIfNotOnCooldown(103641);

                if (BrodiesPluginUI.SASettings.Instance.BookAges)
                    if (BMobList.BookOfTheAges != null)
                        if (!Me.HasAura(147226))
                            UseIfNotOnCooldown(103642);

                if (BrodiesPluginUI.SASettings.Instance.DewMorning)
                    if (BMobList.DewOfEternalMorning != null)
                        if (!Me.HasAura(147476))
                            UseIfNotOnCooldown(103643);
            }

            if (Me.Combat && BMobList.TimelessBirds != null)
            {
                // Gust of Wind
                if (BrodiesPluginUI.SASettings.Instance.GustOfWind)
                    if (BMobList.TimelessBirds.Distance2D <= 15 && BMobList.TimelessBirds.IsCasting && BMobList.TimelessBirds.CastingSpellId == 147310)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.TimelessBirds, 120, 15);
            }

            if (Me.Combat && BMobList.TimelessTurtle != null)
            {
                // Geyser (Elder Great Turtle only)
                if (BrodiesPluginUI.SASettings.Instance.Geyser)
                    if (BMobList.TimelessTurtle.Distance2D <= 15 && BMobList.TimelessTurtle.IsCasting && BMobList.TimelessTurtle.CastingSpellId == 147573)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.TimelessTurtle, 90, 15);

                // Shell Spin
                if (BrodiesPluginUI.SASettings.Instance.ShellSpin)
                {
                    if (BMobList.TimelessTurtle.Location.Distance(Me.Location) <= 15 && (BMobList.TimelessTurtle.CastingSpellId == 147590 || BMobList.TimelessTurtle.HasAura(147590)))
                        KatzerleAvoid.RunAwayCode.FleeingFromEnemy(BMobList.TimelessTurtle, 147590, 20, 10, 5);

                    if (BMobList.TimelessTurtle.Location.Distance(Me.Location) <= 15 && (BMobList.TimelessTurtle.CastingSpellId == 147571 || BMobList.TimelessTurtle.HasAura(147571)))
                        KatzerleAvoid.RunAwayCode.FleeingFromEnemy(BMobList.TimelessTurtle, 147571, 20, 10, 5);
                }
            }

            if (Me.Combat && BMobList.TimelessOxen != null)
            {
                // Headbutt
                if (BrodiesPluginUI.SASettings.Instance.Headbutt)
                    if (BMobList.TimelessOxen.Distance2D <= 20 && BMobList.TimelessOxen.IsCasting && (BMobList.TimelessOxen.CastingSpellId == 147382 || BMobList.TimelessOxen.CastingSpellId == 147384))
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.TimelessOxen, 120, 20);

                // Ox Charge
                if (BrodiesPluginUI.SASettings.Instance.OxCharge)
                    if (BMobList.TimelessOxen.Distance2D <= 30 && BMobList.TimelessOxen.IsCasting && (BMobList.TimelessOxen.CastingSpellId == 147386 || BMobList.TimelessOxen.CastingSpellId == 147385))
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.TimelessOxen, 120, 30);
            }

            if (Me.Combat && BMobList.TimelessTiger != null)
            {
                // Rending Swipe
                if (BrodiesPluginUI.SASettings.Instance.RendingSwipe)
                    if (BMobList.TimelessTiger.Distance2D <= 15 && BMobList.TimelessTiger.IsCasting && BMobList.TimelessTiger.CastingSpellId == 147646)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.TimelessTiger, 120, 15);

                // Greater Swipe
                if (BrodiesPluginUI.SASettings.Instance.GreaterSwipe)
                    if (BMobList.TimelessTiger.Distance2D <= 15 && BMobList.TimelessTiger.IsCasting && BMobList.TimelessTiger.CastingSpellId == 147652)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.TimelessTiger, 150, 15);
            }

            if (Me.Combat && BMobList.TimelessRock != null)
            {
                // Stomp
                if (BrodiesPluginUI.SASettings.Instance.Stomp)
                {
                    if (BMobList.TimelessRock.Location.Distance(Me.Location) <= 15 && (BMobList.TimelessRock.CastingSpellId == 147500 || BMobList.TimelessRock.HasAura(147500)))
                        KatzerleAvoid.RunAwayCode.FleeingFromEnemy(BMobList.TimelessRock, 147500, 40, 10, 5);

                    if (BMobList.TimelessRock.Location.Distance(Me.Location) <= 15 && (BMobList.TimelessRock.CastingSpellId == 147512 || BMobList.TimelessRock.HasAura(147512)))
                        KatzerleAvoid.RunAwayCode.FleeingFromEnemy(BMobList.TimelessRock, 147512, 40, 10, 5);
                }
            }

            if (Me.Combat && BMobList.SpectralPanda != null)
            {
                // Spinning Crane Kick
                if (BrodiesPluginUI.SASettings.Instance.SpinningCraneKick)
                    if (BMobList.SpectralPanda.Location.Distance(Me.Location) <= 15 && (BMobList.SpectralPanda.CastingSpellId == 148730 || BMobList.SpectralPanda.HasAura(148730)))
                        KatzerleAvoid.RunAwayCode.FleeingFromEnemy(BMobList.SpectralPanda, 148730, 30, 10, 5);
            }

            if (Me.Combat && BMobList.Spineclaw != null)
            {
                // Claw Flurry
                if (BrodiesPluginUI.SASettings.Instance.ClawFlurry)
                    if (BMobList.Spineclaw.Distance2D <= 15 && BMobList.Spineclaw.IsCasting && BMobList.Spineclaw.CastingSpellId == 147557)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.Spineclaw, 120, 15);
            }

            if (Me.Combat && BMobList.Ordon != null)
            {
                // Breath of Fire
                if (BrodiesPluginUI.SASettings.Instance.BreathOfFire)
                    if (BMobList.Ordon.Distance2D <= 15 && BMobList.Ordon.IsCasting && BMobList.Ordon.CastingSpellId == 147416)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.Ordon, 120, 15);

                // Crackling Blow
                if (BrodiesPluginUI.SASettings.Instance.CracklingBlow)
                    if (BMobList.Ordon.Distance2D <= 15 && BMobList.Ordon.IsCasting && BMobList.Ordon.CastingSpellId == 147674)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.Ordon, 120, 15);

                // Blazing Blow
                if (BrodiesPluginUI.SASettings.Instance.BlazingBlow)
                    if (BMobList.Ordon.Distance2D <= 25 && BMobList.Ordon.IsCasting && BMobList.Ordon.CastingSpellId == 148003)
                        BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.Ordon, 120, 25);

                // Burning Sacrifice
                if (BrodiesPluginUI.SASettings.Instance.BurningSacrifice)
                    if (BMobList.Ordon.Distance2D <= 15 && BMobList.Ordon.IsCasting && BMobList.Ordon.CastingSpellId == 147422)
                        KatzerleAvoid.RunAwayCode.FleeingFromEnemy(BMobList.Ordon, 147422, 30, 10, 5);

                // Blazing Cleave
                if (BrodiesPluginUI.SASettings.Instance.BlazingCleave)
                    if (BMobList.Ordon.Distance2D <= 15 && BMobList.Ordon.IsCasting && BMobList.Ordon.CastingSpellId == 147702)
                        KatzerleAvoid.RunAwayCode.FleeingFromEnemy(BMobList.Ordon, 147702, 30, 10, 5);

                // Defensive Shield
                if (BrodiesPluginUI.SASettings.Instance.DefensiveShield)
                    if (Me.CurrentTarget != null && Me.CurrentTarget.HasAura(147689) && !Me.IsSafelyBehind(Me.CurrentTarget) && Me.Location.Distance(Me.CurrentTarget.Location) <= 10)
                    {
                        using (StyxWoW.Memory.ReleaseFrame(true))
                        {
                            while (!Me.IsSafelyBehind(Me.CurrentTarget))
                            {
                                WoWMovement.Move(WoWMovement.MovementDirection.StrafeRight);
                                Me.CurrentTarget.Face();
                            }
                        }
                        WoWMovement.MoveStop();
                    }
            }
            #endregion

            #endregion

            #region Draenor Questing
            
            if (BMobList.Grulloc != null)
                if (BMobList.Grulloc.Distance2D <= 40 && BMobList.Grulloc.IsCasting && BMobList.Grulloc.CastingSpellId == 141290)
                    BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.Grulloc, 90, 40);

            if (BMobList.Grosh != null)
            {
                if (BMobList.Grosh.Distance2D <= 35 && BMobList.Grosh.IsCasting && BMobList.Grosh.CastingSpellId == 165908)
                    BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.Grosh, 150, 35);
                if (!BMobList.Grosh.HasAura(157954) && IsOnQuest(34348) && BMobList.Grosh.Distance2D < 30 && Me.CastingSpellId != 157954)
                {
                    Lua.DoString("ExtraActionButton1:Click()");
                    SpellManager.ClickRemoteLocation(BMobList.Grosh.Location);
                }
            }

            if (Me.HasAura(161918)) // Fiery Ground
                WoWMovement.Move(WoWMovement.MovementDirection.StrafeRight);

            if (BMobList.Clusterpult != null)
                if (BMobList.Clusterpult.Distance2D <= 15 && BMobList.Clusterpult.IsCasting && BMobList.Clusterpult.CastingSpellId == 155243)
                    BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.Clusterpult, 150, 15);
            if (BMobList.Clusterpult != null)
                if (BMobList.Clusterpult.Distance2D <= 15 && BMobList.Clusterpult.IsCasting && BMobList.Clusterpult.CastingSpellId == 155255)
                    BarryDurexAvoid.QuestHelper.AvoidEnemyCast(BMobList.Clusterpult, 150, 15);

            #region Draenor Fishing - Auto use of Fish

            if (BrodiesPluginUI.SASettings.Instance.CrescentSaberfish)
            {
                if (BMobList.SmallCrescentSaberfish != null) ConvertFish(BMobList.SmallCrescentSaberfish, 20);
                if (BMobList.MedCrescentSaberfish != null) ConvertFish(BMobList.MedCrescentSaberfish, 10);
                if (BMobList.LargeCrescentSaberfish != null) ConvertFish(BMobList.LargeCrescentSaberfish, 5);
            }

            if (BrodiesPluginUI.SASettings.Instance.SeaScorpion)
            {
                if (BMobList.SmallSeaScorpion != null) ConvertFish(BMobList.SmallSeaScorpion, 20);
                if (BMobList.MedSeaScorpion != null) ConvertFish(BMobList.MedSeaScorpion, 10);
                if (BMobList.LargeSeaScorpion != null) ConvertFish(BMobList.LargeSeaScorpion, 5);
            }

            if (BrodiesPluginUI.SASettings.Instance.FireAmmonite)
            {
                if (BMobList.SmallFireAmmonite != null) ConvertFish(BMobList.SmallFireAmmonite, 20);
                if (BMobList.MedFireAmmonite != null) ConvertFish(BMobList.MedFireAmmonite, 10);
                if (BMobList.LargeFireAmmonite != null) ConvertFish(BMobList.LargeFireAmmonite, 5);
            }

            if (BrodiesPluginUI.SASettings.Instance.FatSleeper)
            {
                if (BMobList.SmallFatSleeper != null) ConvertFish(BMobList.SmallFatSleeper, 20);
                if (BMobList.MedFatSleeper != null) ConvertFish(BMobList.MedFatSleeper, 10);
                if (BMobList.LargeFatSleeper != null) ConvertFish(BMobList.LargeFatSleeper, 5);
            }
            
            if (BrodiesPluginUI.SASettings.Instance.AbyssalGulperEel)
            {
                if (BMobList.SmallAbyssalGulperEel != null) ConvertFish(BMobList.SmallAbyssalGulperEel, 20);
                if (BMobList.MedAbyssalGulperEel != null) ConvertFish(BMobList.MedAbyssalGulperEel, 10);
                if (BMobList.LargeAbyssalGulperEel != null) ConvertFish(BMobList.LargeAbyssalGulperEel, 5);
            }

            if (BrodiesPluginUI.SASettings.Instance.JawlessSkulker)
            {
                if (BMobList.SmallJawlessSkulker != null) ConvertFish(BMobList.SmallJawlessSkulker, 20);
                if (BMobList.MedJawlessSkulker != null) ConvertFish(BMobList.MedJawlessSkulker, 10);
                if (BMobList.LargeJawlessSkulker != null) ConvertFish(BMobList.LargeJawlessSkulker, 5);
            }

            if (BrodiesPluginUI.SASettings.Instance.BlindLakeSturgeon)
            {
                if (BMobList.SmallBlindLakeSturgeon != null) ConvertFish(BMobList.SmallBlindLakeSturgeon, 20);
                if (BMobList.MedBlindLakeSturgeon != null) ConvertFish(BMobList.MedBlindLakeSturgeon, 10);
                if (BMobList.LargeBlindLakeSturgeon != null) ConvertFish(BMobList.LargeBlindLakeSturgeon, 5);
            }

            if (BrodiesPluginUI.SASettings.Instance.BlackwaterWhiptail)
            {
                if (BMobList.SmallBlackwaterWhiptail != null) ConvertFish(BMobList.SmallBlackwaterWhiptail, 20);
                if (BMobList.MedBlackwaterWhiptail != null) ConvertFish(BMobList.MedBlackwaterWhiptail, 10);
                if (BMobList.LargeBlackwaterWhiptail != null) ConvertFish(BMobList.LargeBlackwaterWhiptail, 5);
            }

            #endregion

            #region Draenor Items

            if (BrodiesPluginUI.SASettings.Instance.WhisperingCrystal)
            {
                if (BMobList.WhisperingCrystal != null)
                    if (!Me.HasAura(176151))
                        UseIfNotOnCooldown(118922);
            }

            if (BrodiesPluginUI.SASettings.Instance.AutoUseLures)
            {
                if (Me.CastingSpellId == 131476)
                {
                    // Check by zone or by quest to activate lure
                    if (Me.ZoneId == 6720 || IsOnQuest(35066))
                    {
                        if (!Me.HasAura(158036) && BMobList.AmmoniteLure != null)
                            UseIfNotOnCooldown(110291);
                    }
                    if (Me.ZoneId == 6722 || IsOnQuest(35075))
                    {
                        if (!Me.HasAura(158038) && BMobList.GulperEelLure != null)
                        {
                            UseIfNotOnCooldown(110293);
                        }
                    }
                    if (Me.ZoneId == 6721 || IsOnQuest(35071))
                    {
                        if (!Me.HasAura(158031) && BMobList.SkulkerLure != null)
                            UseIfNotOnCooldown(110274);
                    }
                    if (Me.ZoneId == 6755 || IsOnQuest(35072))
                    {
                        if (!Me.HasAura(158034) && BMobList.SleeperLure != null)
                            UseIfNotOnCooldown(110289);
                    }
                    if (Me.ZoneId == 6719 || IsOnQuest(35073))
                    {
                        if (!Me.HasAura(158035) && BMobList.SturgeonLure != null)
                            UseIfNotOnCooldown(110290);
                    }
                    if (Me.ZoneId == 6662 || IsOnQuest(35074))
                    {
                        if (!Me.HasAura(158039) && BMobList.WhiptailLure != null)
                            UseIfNotOnCooldown(110294);
                    }
                }
            }

            #endregion

            #endregion

            #region Holiday Special Quests

            if (BMobList.HandfulOfTreats != null)
                UseIfNotOnCooldown(BMobList.HandfulOfTreats.Entry);
            if (Me.HasAura(24740))
                Me.GetAuraById(24740).TryCancelAura();
            if (Me.HasAura(24723))
                Me.GetAuraById(24723).TryCancelAura();
            if (Me.HasAura(24732))
                Me.GetAuraById(24732).TryCancelAura();
            if (Me.HasAura(172003))
                Me.GetAuraById(172003).TryCancelAura();
            if (Me.HasAura(172008))
                Me.GetAuraById(172008).TryCancelAura();
            if (Me.HasAura(172010))
                Me.GetAuraById(172010).TryCancelAura();
            if (Me.HasAura(172015))
                Me.GetAuraById(172015).TryCancelAura();
            if (Me.HasAura(172020))
                Me.GetAuraById(172020).TryCancelAura();

            #endregion

        }
		#endregion

        public void ConvertFish(WoWItem item, int count)
        {
            if (item.StackCount >= count)
                UseIfNotOnCooldown(item.Entry);
        }
		
		public static void ChangeProfile(string Profile)
		{
			Logging.Write(Colors.LightSkyBlue, "[Brodies Plugin] Profile Swapper: Loading Profile");
			WoWMovement.MoveStop();
			LoadProfile(Profile);
			Logging.Write(Colors.LightSkyBlue, "[Brodies Plugin] Profile Swapper: Profile Loaded");
		}
		
		public static string DetermineActiveProfile()
		{
			if (BrodiesPluginUI.BPSettings.Instance.Active1)
			{
				BrodiesPluginUI.BPSettings.Instance.Active1 = false;
                return global::BrodiesPlugin.Properties.Resources._Rep__Golden_Lotus_Dailies__Brodie_;
			}
			else if (BrodiesPluginUI.BPSettings.Instance.Active2)
			{
				BrodiesPluginUI.BPSettings.Instance.Active2 = false;
                return global::BrodiesPlugin.Properties.Resources._Rep__Tillers_Dailies__Brodie_;
			}
			else if (BrodiesPluginUI.BPSettings.Instance.Active3)
			{
				BrodiesPluginUI.BPSettings.Instance.Active3 = false;
                return global::BrodiesPlugin.Properties.Resources._Rep__Cloud_Serpent_Dailies__Brodie_;
			}
			else if (BrodiesPluginUI.BPSettings.Instance.Active4)
			{
				BrodiesPluginUI.BPSettings.Instance.Active4 = false;
                return global::BrodiesPlugin.Properties.Resources._Rep__The_Anglers_Dailies__Brodie_;
			}
			else if (BrodiesPluginUI.BPSettings.Instance.Active5)
			{
				BrodiesPluginUI.BPSettings.Instance.Active5 = false;
                if (Me.IsAlliance)
                    return global::BrodiesPlugin.Properties.Resources._Rep__Shieldwall__Brodie_;
                else
                    return global::BrodiesPlugin.Properties.Resources._Rep__Dominance__Brodie_;
			}
			else if (BrodiesPluginUI.BPSettings.Instance.Active6)
			{
				BrodiesPluginUI.BPSettings.Instance.Active6 = false;
                return global::BrodiesPlugin.Properties.Resources._Rep__The_Klaxxi_Dailies__Brodie_;
			}
			else if (BrodiesPluginUI.BPSettings.Instance.Active7)
			{
				BrodiesPluginUI.BPSettings.Instance.Active7 = false;
                return global::BrodiesPlugin.Properties.Resources._Rep__Shado_Pan_Dailies__Brodie_;
			}
			else if (BrodiesPluginUI.BPSettings.Instance.Active8)
			{
				BrodiesPluginUI.BPSettings.Instance.Active8 = false;
                if (Me.IsAlliance)
                    return global::BrodiesPlugin.Properties.Resources._Rep__Isle_of_Thunder_A__Brodie_;
                else
                    return global::BrodiesPlugin.Properties.Resources._Rep__Isle_of_Thunder_H__Brodie_;
			}
			else if (BrodiesPluginUI.BPSettings.Instance.Active9)
			{
				BrodiesPluginUI.BPSettings.Instance.Active9 = false;
                if (Me.IsAlliance)
                    return global::BrodiesPlugin.Properties.Resources._Rep__Isle_of_Thunder_PvP_A__Brodie_;
                else
                    return global::BrodiesPlugin.Properties.Resources._Rep__Isle_of_Thunder_PvP_H__Brodie_;
			}
			else if (BrodiesPluginUI.BPSettings.Instance.Active10)
			{
				BrodiesPluginUI.BPSettings.Instance.Active10 = false;
                return global::BrodiesPlugin.Properties.Resources._Rep__August_Celestials_Dailies__Brodie_;
			}
			else if (BrodiesPluginUI.BPSettings.Instance.Active11)
			{
				BrodiesPluginUI.BPSettings.Instance.Active11 = false;
                return global::BrodiesPlugin.Properties.Resources._Rep__Nat_Pagle_Dailies__TBMP_;
			}
			/*else if (BrodiesPluginUI.BPSettings.Instance.Active12)
			{
				BrodiesPluginUI.BPSettings.Instance.Active12 = false;
				Logging.WriteDiagnostic(Colors.LightSkyBlue, "[Brodies Plugin] Profile Swapper has run out of profiles to use. Thank you come again!");
				return BrodiesPluginUI.BPSettings.Instance.Profile12;
			} */
			else
			{
				SpellManager.StopCasting();
				Logging.Write(Colors.LightSkyBlue, "[Brodies Plugin] Profile Swapper: No profiles left by selection. Halting bot.");
				TreeRoot.Stop("Bot stop requested by Brodies Plugin: Lack of continuing profile selection.");
				return null;
			}
		}
		
		static public string FolderPath
		{
			get
			{
				string sPath = Process.GetCurrentProcess().MainModule.FileName;
				sPath = Path.GetDirectoryName(sPath);
				sPath = Path.Combine(sPath, "Plugins\\BrodiesPlugin\\");
				return sPath;
			}
		}

        static public void LoadProfile(string fileContent)
        {
            /// <remarks>"Created by Mirabis on 10/25/2014</remarks>
            if (string.IsNullOrEmpty(fileContent)) return;
            Styx.CommonBot.Profiles.ProfileManager.LoadNew(new MemoryStream(Encoding.UTF8.GetBytes(fileContent)));
        }

        public static void LoadProfileByName(string profileName)
        {
            var fileContent = global::BrodiesPlugin.Properties.Resources.ResourceManager.GetString(profileName);
            LoadProfile(fileContent);
        }

		static public bool InPetCombat()
		{
			List<string> cnt = Lua.GetReturnValues("dummy,reason=C_PetBattles.IsTrapAvailable() return dummy,reason");

			if (cnt != null) { if (cnt[1] != "0") return true; }
			return false;
		}
	}
}